var userId = 0;
var userEwm='';
var userinfodata='';
var childMess={};
var nums=0;
var interval="";
var timer=0;
//查看更多
$(".moreBtnDiv").click(function(){
   $(".moreDivs").slideToggle("slow")
   if($(this).find("span").text()=="查看全部"){
	   $(".iconDiv").addClass("am-hide")
	   $(this).find("span").text("收起")
	   $(this).find("i").addClass("am-icon-angle-up").removeClass("am-icon-angle-down");
   }else if($(this).find("span").text()=="收起"){
	   $(".iconDiv").removeClass("am-hide")
	   $(this).find("span").text("查看全部")
	   $(this).find("i").addClass("am-icon-angle-down").removeClass("am-icon-angle-up");
   }  
})
//游客点击头像登录
$(".imgDivs").click(function(){
	var url=$(this).find("img").attr("src")
	if(url=="../img/tourist.png"){
		window.location.href = "login.html"
	}else if(url=="../img/noChild.jpg"){
		window.location.href = "personal/child_list.html"
	}
})
//完善孩子信息
$("#userName").click(function(){
	if($(this).html()=="完善孩子信息"){
		window.location.href = "personal/child_list.html"
	}
})
//上课记录
function recordClass(){
	if(slf.checkSign()){
		//已登录
		slf.getSequenceChild();
		if(slf.schoolId=='a'||slf.schoolId==undefined||slf.schoolId==''){
			var messPrompt="请先完善孩子信息，是否现在去完善？"
			$("#class_model .am-modal-bd").html(messPrompt)
			$("#class_model").modal({
				closeViaDimmer: false,
				onConfirm: function(options) {
					window.location.href = "personal/child_list.html"
		        },
			});
		}else{
			window.location.href = "class_record.html"
		}
	}else{
		//未登录
		var messPrompt="此功能仅对登录用户开放，是否需要登录？"
		$(".operationModalBody").html(messPrompt)
		$("#operationModal").modal({
			closeViaDimmer: false,
			onConfirm: function() {
				window.location.href = "login.html"
	        },
	        onCancel: function() {
	          
	        }
		})
	}
}
//剩余课时
function timeClass(){
	if(slf.checkSign()){
		//已登录
		slf.getSequenceChild();
		if(slf.schoolId=='a'||slf.schoolId==undefined||slf.schoolId==''){
			var messPrompt="请先完善孩子信息，是否现在去完善？"
			$("#class_model .am-modal-bd").html(messPrompt)
			$("#class_model").modal({
				closeViaDimmer: false,
				onConfirm: function(options) {
					window.location.href = "personal/child_list.html"
		        },
			});
		}else{
			window.location.href = "class_time.html"
		}
	}else{
		//未登录
		var messPrompt="此功能仅对登录用户开放，是否需要登录？"
		$(".operationModalBody").html(messPrompt)
		$("#operationModal").modal({
			closeViaDimmer: false,
			onConfirm: function(options) {
				window.location.href = "login.html"
	        },
	        onCancel: function() {
	          
	        }
		})
	}
}
//进入商城
function seeShopp(){
	window.location.href = "shopp.html"
}
//进入个人中心
function checkPer(){
	if(slf.checkSign()){
		//已登录
		window.location.href = "personal/index.html"
	}else{
		//未登录
		window.location.href = "personal/noLogin.html"
	}
}
$(function () {
	slf.ajax({
        url:'/firstLogin',
        type:'post',
        async : false,
        success:function(data){
           if(data==1){
        	   //已登录
        	   console.log("已登录")
    		   childMess=slf.getSequenceChild();
        	   if(slf.schoolId=='a'||slf.schoolId==undefined||slf.schoolId==null){
        		   
        	   }else{
        		   var ageArr=[];
        		   ageArr=childMess.age.split("-");
        		   $("#userAge").html(childMess.age) 
        	   }
    			slf.ajax({
    				url:'/userSystemMessage/getUserMessage',
    				type:'get',
    				success:function(data){
    					if(slf.schoolId=='a'||slf.schoolId==undefined||slf.schoolId==null){
    						$(".imgDivs").append("<img src='../img/noChild.jpg' />")
    						$("#userName").html("完善孩子信息")
    						getCourseReservation();
    						getArticle();
    					}else{
    						getdata();
        					userMessage(data);
    					}
    				},error:function(){
    					console.log("失败")
    				}
    			});
           }else{
        	   console.log("未登录")
        	   //游客
        	   $("#userName").html("游客");
        	   $(".imgDivs").append("<img src='../img/tourist.png' style='width:50px;height:50px;margin-top:15px;' />")
        	   getCourseReservation();
        	   getArticle();
           }
        }
	})
});

function getdata(){
    slf.ajax({
		url:'/client/getUserInfo',
		type:'get',
		success:function(data){
			userinfodata=data;
			slf.ajax({
				url:'/myCenter/getUserChildrenCourse',
				type:'post',
				param:JSON.stringify({type: "0"}),
				contentType : 'application/json;charset=utf-8',
				success:function(data){
					userInfo(userinfodata,data);
				}
			});
			
		},error:function(){
			console.log("失败")
		}
	});
	
}
//获取文章
function getArticle(){
	slf.ajax({
		url:'/client/getArticle',
		type:'get',
		param:{type:1,size:2},
		success:function(data){
			console.log("获取文章")
			console.log(data)
			var htmlArticle='';
			if(data.res==1&&data.obj.length>0){
				for(var i=0,b=data.obj.length;i<b;i++){
					htmlArticle+='<li class="appointLi articleLi" onclick="javascript:window.location.href=\'article_details.html?article_id='+data.obj[i].article_id+' \'">'
					htmlArticle+='<div class="appointDivs">'  
					htmlArticle+='<div class="curriculumImg  am-u-sm-4 pad-0 am-u-md-3">'
					if(data.obj[i].article_background!=''&&data.obj[i].article_background!=undefined &&data.obj[i].article_background!=null){
						htmlArticle+='<img src="'+data.obj[i].article_background+'" /></div>'
					}else{
						var image=slf.defau.courseIcon(data.obj[i].article_id);
						htmlArticle+='<img src="'+image+'" /></div>'
					}         
					htmlArticle+='<ul class="appointMess  am-u-sm-8 pad-0 am-u-md-9">'       
					htmlArticle+='<li class="titleLiArticle">'+data.obj[i].title+'</li>'          
					htmlArticle+='<li class="timeArticle">发布日期：'+data.obj[i].create_date+'</li></ul></div>'           
			        htmlArticle+='<div class="classBelt"></div></li>'  
			        
				}
				$('#article').html(htmlArticle);
			}else{
				//TODO无数据的时候文章展示
				htmlArticle+='<li class="noMessDiv">暂无相关信息~看看其他的吧~</li>'
				$('#article').html(htmlArticle);
			}	
		}
		
	});
}
//获取预约课程
function getCourseReservation(){
	$("#course").html("");
	window.clearInterval(timer);
	window.clearTimeout(timer);
	slf.ajax({
		url:'/recentlyMadeReservations/checkLimitRecentlyMadeReservations',
		success:function(data){
			console.log("获取预约返回值")
			console.log(data)
			if(data.res==1&&data.obj.length>0){
				order(data);
			}else{
				var html='<li class="noMessDiv">暂无相关信息~看看其他的吧~</li>'
			    $("#course").append(html)
			}
		}
	});
	
}

//消息图标展示
var userMessage= function(data){
	//TODO 有消息时 消息图片旁边的 红色小图片未出现
	if(data.obj.length>0){
		$('.icon-xinxi.am-icon-sm').addClass('posi-rela');
	}else{
		$('.icon-xinxi.am-icon-sm').removeClass('posi-rela');
	}
}

//用户基本信息
var userInfo = function (json,data2) {
    userId = json.obj[0].user_id;
    console.log(data2.obj[0].headPortrait)
    if(data2.obj[0].headPortrait!=''&& data2.obj[0].headPortrait!=null&&data2.obj[0].headPortrait!=undefined){
    	$(".imgDivs").append("<img src='"+data2.obj[0].headPortrait+"' />")
    }else{
    	if(slf.perSex==0){
    		//男宝宝
    		$(".imgDivs").append("<img src='../img/boy.png' />")
    	}else{
    		//女宝宝
    		$(".imgDivs").append("<img src='../img/girl.png' />")
    	}
    }
    for(var a=0,b=data2.obj.length;a<b;a++){
    	if(data2.obj[0].name==undefined||data2.obj[0].name==null||json.obj[0].name==''){
	    	$("#userName").text("完善孩子信息");
	    }
    	if(data2.obj[a].sequence==0){
    	    $("#userName").text(data2.obj[a].name);
    		if(data2.obj[a].height==undefined||data2.obj[a].height==null||data2.obj[a].height==''){
    	    	$(".height").addClass("am-hide")
    	    }else{
    	    	$(".height").removeClass("am-hide")
    	    	$("#userHeigh").html(data2.obj[a].height+"cm")
    	    }
    	    if(data2.obj[a].weight==undefined||data2.obj[a].weight==null||data2.obj[a].weight==''){
    	    	$(".weight").addClass("am-hide")
    	    }else{
    	    	$(".weight").removeClass("am-hide")
    	    	$("#userWeight").html(data2.obj[a].weight+"kg")
    	    }
    	}
    }
    getCourseReservation();
	getArticle();
    //TODO 需要替换首页中头像图片
    //$("#head_portrait").attr("src", json.obj[0].head_portrait);
    userEwm=json.obj[0].children_qr_code;

}
/*点击二维码  弹窗*/
$("body").on("click", ".ewm_div", function () {
	if(slf.checkSign()){
		//已登录
		if (userId != 0) {
	    	$('#my-alert').find('.am-modal-bd.am-padding-lg.radius20').html('<img src="'+userEwm+'" />')
	    	$('#my-alert').modal("open");
	    } else {
	    	var messPrompt="请先完善孩子信息，是否现在去完善？"
			$("#class_model .am-modal-bd").html(messPrompt)
			$("#class_model").modal({
				closeViaDimmer: false,
				onConfirm: function(options) {
					window.location.href = "personal/child_list.html"
		        },
			});
	    }
	}else{
		//未登录
		var messPrompt="此功能仅对登录用户开放，是否需要登录？"
			$(".operationModalBody").html(messPrompt)
			$("#operationModal").modal({
				closeViaDimmer: false,
				onConfirm: function(options) {
					window.location.href = "login.html"
		        },
		        onCancel: function() {
		          
		        }
			})
	}
});
//最近预约
var order = function (data) {
    var orderCourse = ""
    var NoOrderCourse = ""
    var course = data.obj;
//当前时间
    var timestamp = Date.parse(new Date());
    var html="";
    timer = setInterval(function () {
        var newList = getLastTime(course);
    }, 1000)
    for (var i = 0,b=course.length; i <b; i++) {
    	html+='<li class="appointLi">'
    	if(course[i].dataType==2){
    		//课包
    		html+='<div class="appointDivs am-g" onclick="showDetail('+course[i].course_page_id+')">'
    	}else if(course[i].dataType==1){
    		//课程
    		if(course[i].courseType==1){//b类课程
    			html+='<div class="appointDivs am-g" onclick="showInDetails('+course[i].course_id+','+course[i].school_course_page_id+')">'
    		}else{//c类课程
    			html+='<div class="appointDivs am-g" onclick="showInDetail('+course[i].course_page_id+','+course[i].id+','+i+')">'
    		}
    	}
    	html+='<div class="curriculumImg am-u-sm-4 pad-0 am-u-md-3">'
		if(course[i].cover_picture==undefined||course[i].cover_picture==null||course[i].cover_picture==''){
			if(course[i].dataType==2){
				var coverImg=slf.defau.courseIcon(course[i].course_page_id)
			}else if(course[i].dataType==1){
				if(course[i].course_page_id==undefined||course[i].course_page_id==''){
					var coverImg=slf.defau.courseIcon(course[i].course_id)
				}else{
					var coverImg=slf.defau.courseIcon(course[i].course_page_id)
				}
			}
			html +='<img src="'+coverImg+'" /></div>'
		}else{
			html +='<img src="'+course[i].cover_picture+'" /></div>'
		}           
    	html+='<ul class="appointMess am-u-sm-8 pad-0 am-u-md-9">'       
    	html+='<li class="titleLi">'
    	html+='<span class="titleDiv">'+course[i].name+'</span>' 
    	if(course[i].dataType==1){
    		//课程
    		if(course[i].syClassroomNumber==undefined||course[i].syClassroomNumber==null){
    			html+='<span class="rePosition"></span></li>'
    		}else{
    			if(course[i].syClassroomNumber==0){
    				html+='<span class="rePosition" style="font-size:12px;">已满员</span></li>'
    			}else if(course[i].syClassroomNumber<7){
    				html+='<span class="rePosition" style="font-size:12px;">余位：'+course[i].syClassroomNumber+'</span></li>'
    			}else{
    				html+='<span class="rePosition" style="font-size:12px;color:#26E232">余位：'+course[i].syClassroomNumber+'</span></li>'
    			}
    		}
    	}
    	if(course[i].dataType==1){
    		//课程
    		html+='<li class="addrLi" style="height:20px;">'
			if(course[i].brief_introduction!=undefined){
				html+='<span class="descs">简介：'+course[i].brief_introduction+'</span>'
			}
	    	html+='</li>'
    	}else{
    		html+='<li class="addrLi">'
			if(course[i].brief_introduction!=undefined){
				html+='<span class="desc">简介：'+course[i].brief_introduction+'</span>'
			}
	    	html+='</li>'
    	}
    	html+='<li class="timeLi">'
    	if(course[i].dataType==1){
    		//课程
    		html+='<span class="addrs">地点：'+ course[i].schoolName +'</span>'
    	}else if(course[i].dataType==2){
    		//课包
    		html+='<span class="addrs">地点：'+ course[i].schoolName +'</span>'
    	}        
    	html+='</li>'
    	if(course[i].dataType==1){
    		if(course[i].classroomName==undefined){
    			html+='<li class="timeLi">'
    	    	html+='<span class="addrs">场馆：'+ course[i].classRoomName +'</span>'
    	    	html+='</li>'
    		}else{
    			html+='<li class="timeLi">'
    	    	html+='<span class="addrs">场馆：'+ course[i].classroomName +'</span>'
    	    	html+='</li>'
    		}
    	}
    	if(course[i].dataType==1){
			html+='<li class="timeLi">'
			html+='<span class="addrs">时间：'+ course[i].courseTime +'</span>'
			html+='</li>'
    	}
    	html+='</ul></div>'      
    	html+='<div class="classOpen" style="min-height:16px">'
		if(course[i].dataType==1){
			//课程
			if(course[i].countDown<-3600){
				html+='<span class="classTime" style="font-size:13px;color:#26E232">进行中</span>'
			}else if(course[i].countDown<0&&course[i].countDown>-3600){
				html+='<span class="classTime" style="font-size:13px;color:#888">课程已结束</span>'
			}else if(course[i].countDown<14400){
				html+='<span class="classTime" style="font-size:13px;color:#26E232">课程即将开始</span>'
			}else{
				html+='<span class="classTime" style="font-size:13px;">距离开课：<span class="coutDownTime" id="timers'+i+'"></span></span>'
			}
			
		}else if(course[i].dataType==2){
			html+='<span class="classTime" style="font-size:13px;">销售时间：'+course[i].sales_start_date+'至'+course[i].sales_end_date+'</span>'
		} 
    	if(course[i].dataType==2){
    		//课包
    		if(course[i].discount_price==undefined||course[i].discount_price==null||course[i].discount_price==''){
		    	var money=course[i].price
		    }else{
		    	var money=course[i].discount_price
		    }
    		html+='<span class="classStatus goBuy" money="'+money+'" school_course_page_id="'+course[i].school_course_page_id+'">立即购买</span></div>'
    	}else if(course[i].dataType==1){
    		//课程
    		if(course[i].course_type==2){
    			//b类
    			if(course[i].courseSate==3){
    				//取消
    				html+='<span class="classStatus cancleBtn" style="background:#0A92F8;color:#fff" ids='+course[i].id+'>取消</span></div>'
    			}else if(course[i].courseSate==2){
    				//排队中
    				html+='<span class="classStatus" style="background:#fffbf2;color:#ff2f2a;border:none;">排队中</span></div>'
    			}else if(course[i].courseSate==1){
    				//(立即排队)
    				if(course[i].discount_price==undefined||course[i].discount_price==null||course[i].discount_price==''){
    			    	var money=course[i].price
    			    }else{
    			    	var money=course[i].discount_price
    			    }
    				html+='<span class="classStatus" style="background:#FF4646;" onclick="lineUp('+course[i].course_page_id+','+money+')">立即排队</span></div>'
    			}
    		}else if(course[i].course_type==3){
    			//c类
    			if(course[i].discount_price==undefined||course[i].discount_price==null||course[i].discount_price==''){
			    	var money=course[i].price
			    }else{
			    	var money=course[i].discount_price
			    }
    			if(course[i].countDown<0){
    				html+='<span class="classStatus" style="background:#FFFAF4"></span></div>'
				}else if(course[i].countDown<14400){
					html+='<span class="classStatus" style="background:#FFFAF4"></span></div>'
				}else{
					if(course[i].courseSate==1){
						//取消预约
						html+='<span class="classStatus cancleCourseBtn" course_page_id="'+course[i].course_page_id+'" ids="'+course[i].id+'" money="'+money+'"" indexs="'+i+'">取消预约</span></div>'
					}else if(course[i].courseSate==0){
						//立即预约
						if(course[i].syClassroomNumber>0){
							html+='<span class="classStatus goBuys" style="background:#FFAD28" money="'+money+'" course_page_id="'+course[i].course_page_id+'" ids="'+course[i].id+'" indexs="'+i+'">立即预约</span></div>'
						}else{
							html+='<span class="classStatus" style="background:#FFFBF2;float:right;font-size:12px;text-align:right;color:#ff2f2a;">已满员</span></div>'
						}
						
					}
					
				}
    			
    		}
    	} 
    	html+='<div class="classBelt"></div></li>'
    }
    $("#course").append(html);
    //点击事件放这里是因为模态窗传值不改变的bug，此为解决方法
    //取消课程
    $(".cancleBtn").on('click', function(e) {
    	$('#class_model .am-modal-bd').html("是否确定取消本课程？");
    	var course_id= $(this).attr('ids');
        var $confirm = $('#class_model');
        var confirm = $confirm.data('amui.modal');
        var onConfirm = function() {
        	cancel(course_id)
        };
        var onCancel = function() {
            
        }
        if (confirm) {
          confirm.options.onConfirm =  onConfirm;
          confirm.options.onCancel =  onCancel;
          confirm.toggle(this);
        } else {
          $confirm.modal({
            relatedElement: this,
            closeViaDimmer: false,
            onConfirm: onConfirm,
            onCancel: onCancel
          });
        }
    })
    //取消预约
    $(".cancleCourseBtn").on('click', function(e) {
    	$(".zcc").removeClass("am-hide");
    	var num=$(this).attr('indexs');
    	var nowTime=$("#timers"+num+"").html();
    	var course_page_id= $(this).attr('course_page_id');
    	var id= $(this).attr('ids');
    	var money= $(this).attr('money');
    	setTimeout(function(){
    		slf.ajax({
                url: "/getCancelMoney",//获取退还立方币
                param : {
                	id:id,
                	seconds:nowTime,
                },
                success: function (data) {
                	console.log("获取退还立方币")
                	console.log(data)
                	if(data.res==1){
                		var returnMoney=data.obj;
                		$('#cancleModal .am-modal-bd').html("如若取消本次预约，预计退还您<span style='color:red'>"+returnMoney+"</span>立方币，是否确定取消本课程？");
                        var $confirm = $('#cancleModal');
                        $(".zcc").addClass("am-hide")
                        var confirm = $confirm.data('amui.modal');
                        var onConfirm = function() {
                        	cancles(id,course_page_id,num)
                        };
                        var onCancel = function() {
                            
                        }
                        if (confirm) {
                          confirm.options.onConfirm =  onConfirm;
                          confirm.options.onCancel =  onCancel;
                          confirm.toggle(this);
                        } else {
                          $confirm.modal({
                            relatedElement: this,
                            closeViaDimmer: false,
                            onConfirm: onConfirm,
                            onCancel: onCancel
                          });
                        }
                	}
                	
                }
            });
    	},1)
    })
    //立即预约
    $(".goBuys").on('click', function(e) {
    	nums++;
    	$(".zcc").removeClass("am-hide");
    	var num=$(this).attr('indexs');
    	var course_page_id= $(this).attr('course_page_id');
    	var id= $(this).attr('ids');
    	var money= $(this).attr('money');
    	setTimeout(function(){
        	if(nums==1){
        		if(slf.checkSign()){
        			var childMess=slf.getSequenceChild();
        			if(slf.schoolId=='a'||slf.schoolId==undefined||slf.schoolId==null){
        				$(".zcc").addClass("am-hide")
        				var messPrompt="请先完善孩子信息，是否现在去完善？"
    					$("#class_model .am-modal-bd").html(messPrompt)
    					$("#class_model").modal({
    						closeViaDimmer: false,
    						onConfirm: function(options) {
    							window.location.href = "personal/child_list.html"
    				        },
    					});
        				nums=0;
        			}else{
        				console.log(childMess)
        				console.log("获取返回孩子信息")
        				if(childMess.state==0){//无期望上课时间
        					console.log("无孩子期望上课时间")
        					$(".zcc").addClass("am-hide")
        					$("#class_model .am-modal-bd").html("您还未选择孩子期望上课时间段，是否现在去完善？")
        					$("#class_model").modal({
        						relatedTarget: this,
        						closeViaDimmer: false,
        						onConfirm: function(options) {
        							window.location.href = "personal/add_child.html?userId="+childMess.userId+"&childrenId="+childMess.childrenId+""; //去其网上可时间  
        						}
        					})
        					nums=0;
        				}else if(childMess.state==1){//you期望上课时间
        					console.log("有孩子期望上课时间");
        					var nowTime=$("#timers"+num+"").html();
        					//判断孩子时间是否被占用以及课程是否已被购买
        					slf.ajax({
        				        url: "/beOccupiedCourse",
        				        param : {
        				        	id:id,
        				        	seconds:nowTime
        				        },
        				        success: function (data) {
        				        	console.log(data)
        				        	console.log("获取是否被占用返回值或者vip或者3小时")
        				        	if(data.res==1){
        				        		//无占用
        								$('#class_model .am-modal-bd').html("是否花费<span class='text-FF2A2A'>"+money+"</span>个立方币预约本课程?");
        								var $confirm = $('#class_model');
        								$(".zcc").addClass("am-hide")
        			                    var confirm = $confirm.data('amui.modal');
        			                    var onConfirm = function() {
        			                    	goBuys(id,course_page_id)
        			                    };
        			                    var onCancel = function() {
        			                    	
        			                    }
        			                    if (confirm) {
        			                      confirm.options.onConfirm =  onConfirm;
        			                      confirm.options.onCancel =  onCancel;
        			                      confirm.toggle(this);
        			                    } else {
        			                      $confirm.modal({
        			                        relatedElement: this,
        			                        closeViaDimmer: false,
        			                        onConfirm: onConfirm,
        			                        onCancel: onCancel
        			                      });
        			                    }
        				        	}else{
        				        		//3小时和vip和占用
        				        		nums=0;
        				        		$("#class_model .am-modal-bd").html(data.resMsg);
        				        		$("#class_model").modal({
        				        			closeViaDimmer: false,
        				        			onConfirm: function(options) {
        				        				window.clearInterval(timer);
        				     	                window.clearTimeout(timer);
        				        				getCourseReservation();
        									}
        				        		});
        				        	}
        				        	nums=0;
        				        }
        				    });
        				}
        			}
        		}else{
        			nums=0;
        			$(".zcc").addClass("am-hide")
        			var messPrompt="此功能仅对登录用户开放，是否需要登录？"
        			$(".operationModalBody").html(messPrompt)
        			$("#operationModal").modal({
        				closeViaDimmer: false,
        				onConfirm: function(options) {
        					window.location.href = "login.html"
        		        },
        		        onCancel: function() {
        		          
        		        }
        			})
        		}
        	}
    	},1)
    	
    })
    //立即购买
    $(".goBuy").on('click', function(e) {
    	$(".zcc").removeClass("am-hide");
    	var coursePageIds= $(this).attr('school_course_page_id');
    	var money= $(this).attr('money');
    	setTimeout(function(){
        	if(slf.checkSign()){
        		var childMess=slf.getSequenceChild();
        		if(slf.schoolId=='a'||slf.schoolId==undefined||slf.schoolId==null){
        			$(".zcc").addClass("am-hide")
        			var messPrompt="请先完善孩子信息，是否现在去完善？"
    				$("#class_model .am-modal-bd").html(messPrompt)
    				$("#class_model").modal({
    					closeViaDimmer: false,
    					onConfirm: function(options) {
    						window.location.href = "personal/child_list.html"
    			        },
    				});
        		}else{
        			console.log(childMess)
        			console.log("获取返回孩子信息")
        			if(childMess.state==0){//无期望上课时间
        				$(".zcc").addClass("am-hide")
        				console.log("无孩子期望上课时间")
        				$("#class_model .am-modal-bd").html("您还未选择孩子期望上课时间段，是否现在去完善？")
        				$("#class_model").modal({
        					closeViaDimmer: false,
        					onConfirm: function(options) {
        						window.location.href = "personal/add_child.html?userId="+childMess.userId+"&childrenId="+childMess.childrenId+""; //去其网上可时间  
        					}
        				})
        			}else if(childMess.state==1){//you期望上课时间
        				console.log("有孩子期望上课时间")
        				$('#class_model .am-modal-bd').html("是否花费<span class='text-FF2A2A'>"+money+"</span>个立方币购买本课程包?");
        				var $confirm = $('#class_model');
        				$(".zcc").addClass("am-hide")
                        var confirm = $confirm.data('amui.modal');
                        var onConfirm = function() {
                        	goBuy(coursePageIds)
                        };
                        var onCancel = function() {
                            
                        }
                        if (confirm) {
                          confirm.options.onConfirm =  onConfirm;
                          confirm.options.onCancel =  onCancel;
                          confirm.toggle(this);
                        } else {
                          $confirm.modal({
                            relatedElement: this,
                            closeViaDimmer: false,
                            onConfirm: onConfirm,
                            onCancel: onCancel
                          });
                        }
        			}
        		}
        	}else{
        		$(".zcc").addClass("am-hide")
        		var messPrompt="此功能仅对登录用户开放，是否需要登录？"
        		$(".operationModalBody").html(messPrompt)
        		$("#operationModal").modal({
        			closeViaDimmer: false,
        			onConfirm: function(options) {
        				window.location.href = "login.html"
        	        },
        	        onCancel: function() {
        	          
        	        }
        		})
        	}
    	},1)
    })
}
/*********************课程预约*******************************/
/*跳转课程包详情页面*/
function showDetail(coursePageId){
	window.location.href='basepkg.html?coursePage='+coursePageId+'&order=y'
}
/*跳转c类课程详情*/
function showInDetail(courseId,id,num){//小包Id
	var nowTime=$("#timers"+num+"").html();
	if(slf.checkSign()){
		//已登录
		var flag=1;
	}else{
		//未登录
		var flag=0;
	}
	window.location.href='basepkg_details.html?courseId='+courseId+'&id='+id+'&flag='+flag+'&nowTime='+encodeURI(encodeURI(nowTime))+'';
}
/*跳转b类课程课程详情*/
function showInDetails(courseId,coursePageId){//小包Id
	window.location.href='basepkg_details.html?courseId='+courseId+'&coursePageIds='+coursePageId;
}
//倒计时
function getLastTime(data){
	for (var i = 0; i < data.length; i++) {
		if(data[i].dataType==1){
			if(data[i].courseType==1||data[i].course_type==3){
				var intDiff = data[i].countDown;//获取数据中的时间戳 
			      var day = 0, hour = 0, minute = 0, second = 0;
			      if (intDiff > 0) {//转换时间  
			        day = Math.floor(intDiff / (60 * 60 * 24));
			        hour = Math.floor(intDiff / (60 * 60)) - (day * 24);
			        minute = Math.floor(intDiff / 60) - (day * 24 * 60) - (hour * 60);
			        second = Math.floor(intDiff) - (day * 24 * 60 * 60) - (hour * 60 * 60) - (minute * 60);
			        if (day <= 9) day = '0' + day;
			        if (hour <= 9) hour = '0' + hour;
			        if (minute <= 9) minute = '0' + minute;
			        if (second <= 9) second = '0' + second;
			        data[i].countDown--;
			        var str = day+'天'+hour + '小时' + minute + '分钟' + second+'秒';
			        $("#timers"+i+"").html(str)
			      }
			} 
		}
	 }
}
//立即排队
function lineUp(course_id,money){
	$('#class_model .am-modal-hd').html("是否花费<span class='text-FF2A2A'>"+money+"</span>个立方币排队此课程?");
	var $confirm = $('#class_model');
    var confirm = $confirm.data('amui.modal');
    var onConfirm = function() {
    	slf.ajax({
            url: "/epOrder/addEPOrder",
            param : {
            	courseId : course_id,
            },
            success: function (data) {
            	console.log(data)
            	console.log("立即排队")
               if(data.res==1){
            	   clearInterval(interval);
            	   $(".alert1").html("排队成功！");
					$('#alert1').modal({
						closeViaDimmer: false,
					})
				   window.clearInterval(timer);
	               window.clearTimeout(timer);
            	   getCourseReservation();
               }
            }
        });
    };
    var onCancel = function() {
        
    }
    if (confirm) {
      confirm.options.onConfirm =  onConfirm;
      confirm.options.onCancel =  onCancel;
      confirm.toggle(this);
    } else {
      $confirm.modal({
        relatedElement: this,
        closeViaDimmer: false,
        onConfirm: onConfirm,
        onCancel: onCancel
      });
    }
    window.clearInterval(timer);
}
//取消
function cancel(course_id){
	slf.ajax({
        url: "/epOrder/updateState",
        param : {
        	id : course_id,
        	state:3,
        },
        success: function (data) {
        	console.log(data)
        	console.log("取消")
           if(data.res==1){
        	   window.clearInterval(timer);
	           window.clearTimeout(timer);
        	   getCourseReservation();
           }
        }
    });
}
//取消预约
function cancles(id,course_id,num){
	var nowTime=$("#timers"+num+"").html();
	console.log(nowTime)
	slf.ajax({
        url: "/cancelCourseTheme",
        param : {
        	courseId : course_id,
        	id:id,
        	seconds:nowTime,
        },
        success: function (data) {
        	console.log(data)
        	console.log("取消预约返回值")
           if(data.res==1){
        	   window.clearInterval(timer);
        	    console.log("取消预约成功");
        	    $(".alert1").html("取消预约成功，已成功给您返回"+data.obj+"立方币！")
        	    $("#alert1").modal('open');
        	    $("#course").html("");
        	    window.clearInterval(timer);
 	            window.clearTimeout(timer);
        	    getCourseReservation();
           }
        }
    });
}
//立即购买B
function goBuy(coursePageIds){
	slf.ajax({
		url:'/myCoursePage/insertMyCoursePage',
		param:{
			courseId:coursePageIds,
			childrenId:childMess.childrenId
		},
		success:function(data){
			console.log(data)
			console.log("判断是否购买")
			var course = data.obj;
			//TODO 后台异常获取抛出有误
			if(data.res != 1){
				if(data.resMsg=="余额不足。"){
					$("#buyMoneyModal").modal({
						relatedTarget: this,
						closeViaDimmer: false,
				        onConfirm: function(options) {
				        	window.location.href = "recharge.html"; //去充值页面
				        },
					});
				}else{
					$("#alert1 .am-modal-bd").html("<span>"+data.resMsg+"</span>");
					$('#alert1').modal("open");
					 window.clearInterval(timer);
			         window.clearTimeout(timer);
					getCourseReservation();
				}
			}else{
				$(".alert1").html("<span>"+data.resMsg+"</span>");
				$('#alert1').modal("open");
				window.clearInterval(timer);
		        window.clearTimeout(timer);
				getCourseReservation();
			}
		}
	});
	
}
//立即预约c
function goBuys(id,courseId){
	slf.ajax({
		url:'/getCourseThemePay',
		param:{
			id:id,
			courseId:courseId,
		},
		success:function(data){
			console.log(data)
			console.log("判断是否购买")
			if(data.obj==0){
				//钱不够
				$("#buyMoneyModal").modal({
					relatedTarget: this,
					closeViaDimmer: false,
			        onConfirm: function(options) {
			        	window.location.href = "recharge.html"; //去充值页面
			        },
				});
				nums=0;
			}else if(data.obj==1){
				//成功
				$("#alert1 .am-modal-bd").html("购买成功！");
				$('#alert1').modal('open');
				$("#course").html("");
				nums=0;
				window.clearInterval(timer);
		        window.clearTimeout(timer);
				getCourseReservation();
			}
		}
	});
}



